Kinetis SDK API Reference Manual  1.0.0-beta
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Bare Metal Abstraction Layer

The Kinetis SDK provides the bare metal abstraction layer for synchronization, mutual exclusion, message queue, etc. More...

Data Structures

struct  sync_object_t
 Type for an synchronization object. More...
 
struct  lock_object_t
 Type for a resource locking object. More...
 
struct  event_object_t
 Type for an event group object. More...
 
struct  msg_queue_t
 Type for a message queue declaration and creation. More...
 
struct  POLL_SLOT_STRUCT
 Poll function slot. More...
 
struct  POLL_STRUCT
 Poll structure. More...
 

Macros

#define kSyncWaitForever   kSwTimerMaxTimeout
 Constant to pass as timeout value in order to wait indefinitely. More...
 
#define FSL_RTOS_CURRENT_TASK   ((task_handler_t)0)
 Macro passed to the task_destroy function to destroy the current task.
 

Typedefs

typedef uint32_t event_group_t
 Type for an event flags group, bit 32 is reserved.
 
typedef void(* task_t )(void *param)
 Type for a task pointer.
 
typedef task_t task_handler_t
 Type for a task handler, returned by the task_create function.
 
typedef uint32_t task_stack_t
 Type for a task stack.
 
typedef msg_queue_tmsg_queue_handler_t
 Type for a message queue declaration and creation.
 
typedef void * msg_queue_item_t
 Type for a message queue item.
 

Synchronization

#define sync_object_declare(obj)   sync_object_t obj
 Create the synchronization object. More...
 

Resource locking

#define lock_object_declare(obj)   lock_object_t obj
 Create the locking object. More...
 

Thread management

#define FSL_RTOS_TASK_DEFINE(task, stackSize, name, usesFloat)   uint8_t fslTaskName_##task[] = name
 Define a task. More...
 
#define task_create(task, priority, param, handler)
 Creates and sets the task to active. More...
 

Message queues

#define MSG_QUEUE_DECLARE(name, number, size)
 This macro statically reserves the memory required for the queue. More...
 

Critical Sections

#define rtos_enter_critical   interrupt_disable_global
 Ensures the following code will not be preempted.
 
#define rtos_exit_critical   interrupt_enable_global
 Allows preemption.
 

Task poll

void Poll (void)
 Poll every function registered in the POLL_STRUCT. More...
 
void POLL_init (void)
 Initialize the POLL_STRUCT. More...
 
#define POLL_MAX_NUM   5
 Maximum number of functions called every time Poll function is invoked.
 

Bare Metal Abstraction Layer

Overview

When RTOSes are not used, a bare metal abstraction layer provides synchronization, mutual exclusion, message queue, and so on.

Task Management

Bare metal abstraction layer provides a poll mechanism to simulate a task. The task functions should not be infinite. When tasks are created, the task functions are registered to a global array and called one by one.This is an example code, which shows how to use a task with a bare metal abstraction layer.
void main(void)
{
task_handler_t handler;
task_create(task_func, priority, param, &handler);
for(;;)
{
Poll();
}
}

Data Structure Documentation

struct sync_object_t

Data Fields

volatile bool isWaiting
 Is any task waiting for a timeout on this object.
 
volatile uint8_t semCount
 The count value of the object.
 
uint8_t timerId
 The software timer channel this object bind to.
 
struct lock_object_t

Data Fields

volatile bool isWaiting
 Is any task waiting for a timeout on this lock.
 
volatile bool isLocked
 Is the object locked or not.
 
uint8_t timerId
 The software timer channel this lock bind to.
 
struct event_object_t

Data Fields

volatile bool isWaiting
 Is any task waiting for a timeout on this event.
 
uint8_t timerId
 The software timer channel this event bind to.
 
volatile event_group_t flags
 The flags status.
 
event_clear_type clearType
 Auto clear or manual clear.
 
struct msg_queue_t

Data Fields

void ** queueMem
 Points to the queue memory.
 
uint16_t number
 Stores the elements in the queue.
 
uint16_t size
 Stores the size in words of each element.
 
uint16_t head
 Index of the next element to be read.
 
uint16_t tail
 Index of the next place to write to.
 
sync_object_t queueSync
 Sync object wakeup tasks waiting for msg.
 
volatile bool isEmpty
 Whether queue is empty.
 
struct POLL_SLOT_STRUCT

Data Fields

task_t p_func
 Task's entry.
 
void * param
 Task's parameter.
 
struct POLL_STRUCT

Data Fields

POLL_SLOT_STRUCT p_slot [POLL_MAX_NUM]
 polling function pointer array
 
uint32_t registered_no
 number of registered function
 

Macro Definition Documentation

#define kSyncWaitForever   kSwTimerMaxTimeout
#define sync_object_declare (   obj)    sync_object_t obj

To be used instead of a standard declaration.

Parameters
objThe sync object to create.
#define lock_object_declare (   obj)    lock_object_t obj

To be used instead of a standard declaration.

Parameters
objThe lock object to create.
#define FSL_RTOS_TASK_DEFINE (   task,
  stackSize,
  name,
  usesFloat 
)    uint8_t fslTaskName_##task[] = name

This macro is used to define resources for a task statically, then task_create will create task based-on these resources.

Parameters
taskThe task function.
stackSizeNumber of elements in the stack for this task.
nameString to assign to the task.
usesFloatBoolean that indicates whether the task uses the floating point unit.
#define task_create (   task,
  priority,
  param,
  handler 
)
Value:
fslTaskName_##task, \
0, \
NULL, \
priority, \
param, \
false, \
handler)
fsl_rtos_status __task_create(task_t task, uint8_t *name, uint16_t stackSize, task_stack_t *stackMem, uint16_t priority, void *param, bool usesFloat, task_handler_t *handler)
Create a task.

This macro is used with FSL_RTOS_TASK_DEFINE to create a task. Here is an example demonstrating how to use:

FSL_RTOS_TASK_DEFINE(task_func, stackSize, taskName, FALSE);
void main(void)
{
task_handler_t handler;
task_create(task_func, priority, param, &handler);
}
Parameters
taskThe task function.
priorityInitial priority of the task.
paramParameter to be passed to the task when it is created.
handlerReturns the identifier to be used afterwards to destroy the task.
Return values
kSuccessThe task was successfully created.
kErrorThe task creation failed.
#define MSG_QUEUE_DECLARE (   name,
  number,
  size 
)
Value:
void * queueMem##name[number]; \
msg_queue_t name = { \
.queueMem = queueMem##name \
}
xQueueHandle msg_queue_t
Type for a message queue declaration and creation.
Definition: fsl_os_abstraction_free_rtos.h:120
Parameters
nameIdentifier for the memory region.
numberNumber of elements in the queue.
sizeSize of every element in words.

Function Documentation

void Poll ( void  )

Every task function registered in the POLL_STRUCT will be called in turn. This function should be used in a infinite loop in main.

Here is an example demonstrating how to use:

int main(void)
{
// System initialize functions.
for(;;)
{
Poll();
}
return 0;
}
void POLL_init ( void  )

The struct POLL_STRUCT must be initialized before task functions are registered.